package com.galaxy.device.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.common.web.core.BaseController;
import com.galaxy.device.domain.DeviceLocation;
import com.galaxy.device.domain.bo.DeviceLocationBo;
import com.galaxy.device.domain.vo.DeviceLocationVo;
import com.galaxy.device.service.IDeviceLocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备位置管理控制器
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/location")
public class DeviceLocationController extends BaseController {

    private final IDeviceLocationService deviceLocationService;

    /**
     * 查询设备位置列表
     */
    @GetMapping("/list")
    @SaCheckPermission("device:location:list")
    public R<List<DeviceLocationVo>> list(DeviceLocationBo bo) {
        return R.ok(deviceLocationService.queryList(bo));
    }

    /**
     * 分页查询设备位置列表
     */
    @GetMapping("/page")
    @SaCheckPermission("device:location:list")
    public TableDataInfo<DeviceLocationVo> page(DeviceLocationBo bo, PageQuery pageQuery) {
        return deviceLocationService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取设备位置详细信息
     */
    @GetMapping("/{id}")
    @SaCheckPermission("device:location:list")
    public R<DeviceLocationVo> getInfo(@PathVariable Long id) {
        DeviceLocationVo info = deviceLocationService.getInfo(id);
        return R.ok(info);
    }

    /**
     * 获取设备位置详细信息
     */
    @GetMapping("/byId/{id}")
    @SaCheckPermission("device:location:list")
    public R<DeviceLocation> getInfoById(@PathVariable Long id) {
        DeviceLocation info = deviceLocationService.getInfoById(id);
        return R.ok(info);
    }

    /**
     * 新增设备位置
     */
    @PostMapping
    @Log(title = "设备位置管理", businessType = BusinessType.INSERT)
    @SaCheckPermission("device:location:add")
    public R<DeviceLocation> add(@Validated @RequestBody DeviceLocationBo bo) {

        return R.ok(deviceLocationService.add(bo));
    }

    /**
     * 修改设备位置
     */
    @PutMapping
    @Log(title = "设备位置管理", businessType = BusinessType.UPDATE)
    @SaCheckPermission("device:location:update")
    public R<DeviceLocation> update(@Validated @RequestBody DeviceLocationBo bo) {

        return R.ok(deviceLocationService.update(bo));
    }

    /**
     * 删除设备位置
     */
    @DeleteMapping("/{id}")
    @Log(title = "设备位置管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:location:delete")
    public R<Void> delete(@PathVariable Long id) {
        deviceLocationService.delete(id);
        return R.ok();
    }

    /**
     * 批量删除设备位置
     */
    @DeleteMapping("/batch/{ids}")
    @Log(title = "设备位置管理", businessType = BusinessType.DELETE)
    @SaCheckPermission("device:location:delete")
    public R<Void> deleteBatch(@PathVariable Long[] ids) {
        deviceLocationService.deleteBatch(ids);
        return R.ok();
    }
}
